home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / asmutil / 80x0393.zip / CPRINT.ASM < prev    next >
Assembly Source File  |  1993-03-30  |  4KB  |  131 lines

  1. ;
  2. ; cprint.asm by Rich Paul
  3. ;
  4. ; This is a direct video color printing routine.  
  5. ; Use in mode three (co80). It's kinda nice.
  6. ;
  7.  
  8. .model small
  9. .code
  10. .286
  11. extrn scroll:far
  12. public cprint
  13.  
  14. ;-----------------------------------------------------------------------------
  15. ; Color Printing Routine -- Direct Video Version -- Use in mode 3 
  16. ; or at your own risk
  17. ;
  18. ; Calling conventions: DS:SI - string to print
  19. ;    DX - location, or FFFF for currant cursor pos
  20. ; String:  Z-Term, 255 preceeds attribute
  21. ; Return:  DX - ending cursor pos
  22. ;    if called with 0 in DX, sets new cursor pos as well
  23.  
  24. cprint proc far
  25.         push    es              ; save ES first, to use as temp
  26.         pusha                   ; save the regs
  27.         push    dx              ; and an extra DX for return
  28.  
  29.         mov     ax,0b800h       ; set the ES to screen
  30.         mov     es,ax
  31.  
  32.         cmp     dx,0FFFFH       ; if =, use current bois pos
  33.         jne     sent            ; otherwise, it came with control
  34.         mov     ah,3            ; Lookin' for the cursor pos.
  35.         mov     bx,0            ; For the currant page
  36.         int     10h             ; OK, so gotta use a bois routine
  37.  
  38. sent:
  39.         push    dx              ; Save the full position
  40.         shr     dx,8            ; and set DX to the row #
  41.         mov     ax,160          ; ax is # of bytes/row
  42.         mul     dl              ; * rows is offset of first byte of row
  43.         pop     dx
  44.         add     al,dl           ; set to 1/2 offset of column
  45.         add     al,dl           ; set to offset of column
  46.         mov     di,ax
  47.         mov     bl,es:[di+1]    ; get currant attribute
  48.  
  49. printl:
  50.         lodsb
  51.         cmp     al,0
  52.         je      printld
  53.         cmp     al,255          ; is this attribute flag?
  54.         jne     printl2         ; nope, print it
  55.  
  56.         lodsb                   ; get the attribute
  57.         mov     bl,al           ; save the attribute
  58.         jmp     printl          ; and continue
  59.  
  60. printl2:
  61.         cmp     al,13           ; how 'bout <CR>?
  62.         je      docr
  63.         cmp     al,10           ; and <LF>?
  64.         je      dolf
  65.  
  66.         inc     dl
  67.         cmp     dl,51h
  68.         jne     printl4
  69.         xor     dl,dl
  70.         inc     dh
  71.         cmp     dh,19h
  72.         jne     printl3
  73.         dec     dh
  74.         call    scroll
  75.         sub     di,160
  76.  
  77. printl3:
  78. printl4:
  79.         stosb
  80.         mov     al,bl
  81.         stosb
  82.  
  83.         jmp     printl
  84.  
  85. printld:
  86.         mov     es,dx           ; save the cursor pos in es
  87.         pop     dx              ; restore extra DX
  88.         cmp     dx,0FFFFH       ; was it called to print at current position?
  89.         jne     sent2           ; if NOT, skip setting
  90.         mov     dx,es           ; get pos back
  91.         mov     ah,02           ; service to set
  92.         xor     bh,bh           ; zero bx
  93.         int     10h             ; and set new cursor pos
  94.  
  95. sent2:
  96.         popa
  97.         mov     dx,es           ; return the cursor pos
  98.         pop     es
  99.         ret
  100.  
  101. docr:
  102.         push    ax
  103.         push    cx
  104.         mov     ax,di
  105.         mov     cl,160
  106.         div     cl
  107.         shr     ax,8            ; move remainder to AX (from ah)
  108.         neg     ax
  109.         add     ax,di
  110.         mov     di,ax           ; set marker to start of currant line
  111.  
  112.         xor     dl,dl           ; set column to 0
  113.         pop     cx
  114.         pop     ax
  115.         jmp     printl
  116.  
  117. dolf:
  118.         inc     dh              ; next line
  119.         cmp     dh,19h          ; off the edge?
  120.         jne     dolf2
  121.         dec     dh
  122.         call    scroll
  123.         jmp     printl
  124.  
  125. dolf2:
  126.         add     di,160          ; move to same pos on next line
  127.         jmp     printl
  128.  
  129. cprint endp
  130. end
  131.